/**
 * 
 */
package com.rad.util;
import java.util.List;

/**
 * @author zpj
 *
 */
public class PageHelper
{
	private int amountPage = 1;
	private int currentPage = 1;
	private List orderlist = null; 
	private int count = 0;
	
	/**
	 * @return Returns the countOrder.
	 */
	public int getCount()
	{
		return count;
	}

	/**
	 * @param countOrder The countOrder to set.
	 */
	public void setCount(int count)
	{
		this.count = count;
	}

	/**
	 * @return Returns the amountPage.
	 */
	public int getAmountPage()
	{
		return amountPage;
	}

	/**
	 * @param amountPage The amountPage to set.
	 */
	public void setAmountPage(int amountPage)
	{
		this.amountPage = amountPage;
	}

	/**
	 * @return Returns the currentPage.
	 */
	public int getCurrentPage()
	{
		return currentPage;
	}

	/**
	 * @param currentPage The currentPage to set.
	 */
	public void setCurrentPage(int currentPage)
	{
		this.currentPage = currentPage;
	}

	/**
	 * @return Returns the orderlist.
	 */
	public List getOrderlist()
	{
		return orderlist;
	}

	/**
	 * @param orderlist The orderlist to set.
	 */
	public void setOrderlist(List orderlist)
	{
		this.orderlist = orderlist;
	}

	public void init(int count)
	{
		if(count > 0)
			amountPage = count / 20;
		if(count % 20 != 0)
			amountPage = amountPage + 1;
	}
	
	public int getPage(String p)
	{
		int cp = 0;
		try
		{
			cp = Integer.parseInt(p);
		}
		catch(Exception e)
		{
			cp = 0;
		}
		currentPage = currentPage + cp;
		if(currentPage < 1)
		{
			currentPage = 1;
			return 1;
		}
		else if(currentPage > amountPage)
		{
			currentPage = amountPage;
			return amountPage;
		}
		else
			return currentPage;
	} 
}
